<script setup lang="ts">
    import { useSearchStore } from '@/store/search'
    import dayjs from 'dayjs'
    import { ref, onUnmounted, onMounted } from 'vue'
    import { useRoute } from 'vue-router'
    const route = useRoute()
    const searchStore = useSearchStore()
    const searchValue = ref<string>('')

    const onSearch = () => {
        searchStore.searchValue = searchValue.value.trim()
    }

    const props = defineProps<{
        getShowDate: (key: string) => void
    }>()

    const zhebaLogo = ref(
        `${import.meta.env.VITE_APP_BASE_URL}/static/image/basketball/zhebalogo.png`
    )

    // 导航按钮
    const menuList = [
        { key: 'today', title: '今天' },
        { key: 'tomorrow', title: '明天' },
        { key: 'yesterday', title: '昨天' },
        { key: 'schedule', title: '赛程' },
        { key: 'team', title: '球队' },
        { key: 'player', title: '球员' },
    ]

    const currentKey = ref<string>('today')

    const handleMenuClick = (key: string) => {
        if (key === 'schedule') {
        } else if (key === 'team') {
        } else if (key === 'player') {
        } else {
            props.getShowDate(key)
        }
        currentKey.value = key
    }
    // 时间
    const timeClock = ref('')
    const timer = ref<number | null>(null)
    const timeFun = () => {
        if (timer.value) {
            clearInterval(timer.value)
        }
        timer.value = setInterval(() => {
            timeClock.value = dayjs().format('YYYY-MM-DD HH:mm:ss')
        }, 1000)
    }
    onMounted(() => {
        timeFun()
    })

    onUnmounted(() => {
        if (timer.value) {
            clearInterval(timer.value)
        }
    })
</script>

<template>
    <a-layout-header class="header">
        <div class="logo">
            <img
                :src="zhebaLogo"
                alt="logo"
                class="logo-img"
            />
            <div class="logo-text">2025淘宝闪购浙江省城市篮球联赛</div>
        </div>
        <div
            class="centerMenu"
            v-if="route.name === 'ZheBaMap'"
        >
            <ul>
                <li
                    v-for="item in menuList"
                    :key="item.key"
                    :class="currentKey === item.key ? 'activeKey' : ''"
                    @click="handleMenuClick(item.key)"
                >
                    {{ item.title }}
                </li>
            </ul>
        </div>
        <a-input-search
            v-if="route.name !== 'ZheBaMap'"
            v-model:value="searchValue"
            placeholder="search"
            class="searchInput"
            @search="onSearch"
        />
        <div class="timeClock">{{ timeClock }}</div>
    </a-layout-header>
</template>

<style scoped lang="less">
    .header {
        background: linear-gradient(#ff291c, #ffef9c);
        padding: 0 20px;
        line-height: 64px;
        color: white;
        font-size: 18px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .logo {
            display: flex;
            align-items: center;

            .logo-img {
                width: 60px;
                margin-right: 10px;
            }

            .logo-text {
                font-size: 20px;
                font-weight: bold;
                color: black;
            }
        }

        .timeClock {
            width: 200px;
            font-size: 18px;
            background: linear-gradient(#000000, #1e1e1e);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .centerMenu {
            line-height: 50px;
            position: relative;
            top: 5px;

            ul {
                display: flex;
                align-items: center;
                width: 600px;

                li {
                    background: linear-gradient(#000000, #030303);
                    -webkit-background-clip: text;
                    -webkit-text-fill-color: transparent;
                    background-clip: text;
                    margin-right: 60px;
                    cursor: pointer;
                    font-weight: 500;
                    border-bottom: solid transparent;
                }

                li:hover {
                    background: linear-gradient(#2f27b7, #5654f4);
                    -webkit-background-clip: text;
                    -webkit-text-fill-color: transparent;
                    background-clip: text;
                }

                .activeKey {
                    border-bottom: solid #5654f4;
                }
            }
        }

        .searchInput {
            width: 400px;
            position: relative;
            left: -100px;
        }
    }
</style>
